package com.videomeetting.legend.videomeetting.activity.service;

import java.io.File;
import java.net.URI;
import java.net.URL;

import android.annotation.SuppressLint;
import android.app.Presentation;
import android.content.Context;
import android.content.SharedPreferences;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.media.MediaPlayer.OnVideoSizeChangedListener;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

import com.videomeetting.legend.videomeetting.R;
import com.videomeetting.legend.videomeetting.activity.ControlActivity;
import com.videomeetting.legend.videomeetting.activity.base.BaseApplication;

import org.video.stream.Mmixer;

@SuppressLint("NewApi")
@SuppressWarnings("unused")
public class HdmiSecPresentation extends Presentation implements OnCompletionListener,
        OnPreparedListener, OnVideoSizeChangedListener, SurfaceHolder.Callback {
    private Mmixer mMixer = null;
//    private ControlActivity.CHInfo[] info = null;
    private MediaPlayer mp = new MediaPlayer();

    private static SurfaceView hdmiSecOutView = null;
    private SurfaceHolder hdmiHolder = null;

    public HdmiSecPresentation(Context outerContext, Display display, Mmixer mixer) {
        super(outerContext, display);

//        Log.d("corelib", ">>>> in HdmiSecPresentation constructor.");
        mMixer = mixer;
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.show);
//        Log.d("corelib", ">>>> in onCreate.");
        hdmiSecOutView = (SurfaceView) findViewById(R.id.show_view);
        hdmiSecOutView.setZOrderOnTop(true);
//        Log.d("corelib", ">>>> setZOrderOnTop true.");
        hdmiHolder = hdmiSecOutView.getHolder();
        hdmiHolder.addCallback(this);

        if (mMixer != null) {
            mMixer.startVSec();
        }
    }

    public void onDismiss() {
        if (mMixer != null) {
//            Log.d("corelib", ">>>>> before stop video sec.");
            mMixer.stopVSec();
        }
    }

    private void FirstrestartPlayVideo() {
        try {
            Thread.sleep(1000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        releaseMediaPlayer();
//		LedTime = 500;
    }
    public void onCompletion(MediaPlayer arg0) {
        try {
            try {
                Thread.sleep(1000);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
    }
    public void onPrepared(MediaPlayer mediaplayer) {
    }

    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
//        Log.d("corelib", ">>>> hdmi surface changed.");
    }
    public void surfaceCreated(SurfaceHolder holder) {
//        Log.d("corelib", ">>>> hdmi surface createed.");
        if (mMixer != null) {
//            Log.d("corelib", ">>>> before detach lsurface.");
            mMixer.detachSSurface();
            mMixer.attachSSurface(holder.getSurface());
//            Log.d("corelib", ">>>> after attach lsurface.");
        }
    }
    public void surfaceDestroyed(SurfaceHolder holder) {
//        Log.d("corelib", ">>>> hdmi destroyed.");
        if (mMixer != null) {
            mMixer.detachSSurface();
        }
    }

    private void startVideoPlayback() {
    }
    public void releaseMediaPlayer() {
    }
}